from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.contrib.auth.decorators import login_required
from skran.models import Project
from skran.projects.form import ProjectForm

"""
    List all projects from one user
"""
@login_required
def list_projects(request):
    
    project_list = None
    
    project_form = ProjectForm() 
    
    if request.method == "GET":
        project_list = list_get(request.user)
    elif request.method == "POST":
        pass
        
    
    return render_to_response('projects-list.html',locals(), context_instance=RequestContext(request))


def list_get(user):
    return Project.objects.filter(user=user); 

"""
    Function to add new project for user
"""
@login_required
def create(request):
    
    project_list = list_get(request.user)
    
    if request.method == "POST":
        
        project_form = ProjectForm(request.POST)
        
        if project_form.is_valid():
            project_form.save(request.user)
            
            
    return render_to_response('projects-list.html',locals(), context_instance=RequestContext(request))